from coin.exchange.base.kr_rest.feed_base import BookHolder
from coin.exchange.base.kr_ws.ws_parser_base import WsFeedHandlerBase
from coin.exchange.bithumb.kr_ws.ws_client import BithumbWSClient
import coin.exchange.bithumb.kr_rest.product as exchange_product


class BithumbWsFeedUpdater(WsFeedHandlerBase):
  def __init__(self, feed_base):
    self.feed_base = feed_base

  def on_book(self, msg):
    self.feed_base.set_book_proto(msg)

  def on_ticker(self, msg):
    pass

  def on_status(self, msg):
    pass

  def on_trade(self, msg):
    pass


class BithumbWsFeedBase(BookHolder):
  ProductType = exchange_product.BithumbProduct

  def __init__(self, product):
    BookHolder.__init__(self, product)
    self.ws_updater = BithumbWsFeedUpdater(self)
    self.ws_client = BithumbWSClient(BithumbWSClient.RequestType.FromSingleProduct(product),
                                     self.ws_updater)
    self.ws_client.start()
